package operation.android.util;

import freemarker.template.TemplateException;
import operation.freeMarker.util.FreemarkerUtil;

import java.io.IOException;
import java.util.Map;

/**
 * Android新增代码
 */
public class AndroidAutoWrite {
    OutFilePath outFilePath = new OutFilePath();
    /**
     * 输出Activity代码
     */
    public String ActivityAutoWrite(Map<String, Object> map) throws IOException, TemplateException {
        FreemarkerUtil.initConfig(0, "XXXActivity.ftl");
        // 生成Activity代码
        FreemarkerUtil.generator(outFilePath.getAndroidOutPath() + outFilePath.activityPath + map.get("classname") + "\\\\" + map.get("ClassName") + "Activity.java", map);
        String res = "SUCCESS 生成【" + map.get("ClassName") + "Activity.java】成功";
        return res;
    }

    /**
     * 输出ViewModel代码
     */
    public String ViewModelAutoWrite(Map<String, Object> map) throws IOException, TemplateException {
        FreemarkerUtil.initConfig(0, "XXXViewModel.ftl");
        // 生成Activity代码
        FreemarkerUtil.generator(outFilePath.getAndroidOutPath() + outFilePath.activityPath + map.get("classname") + "\\\\" + map.get("ClassName") + "ViewModel.java", map);
        String res = "SUCCESS 生成【" + map.get("ClassName") + "ViewModel.java】成功";
        return res;
    }

    /**
     * 输出InfoXML代码
     */
    public String InfoXMLAutoWrite(Map<String, Object> map) throws IOException, TemplateException {
        FreemarkerUtil.initConfig(0, "activity_verification_xxx.ftl");
        // 生成Activity代码
        FreemarkerUtil.generator(outFilePath.getAndroidOutPath() + outFilePath.activity_path + "activity_verification_" + map.get("class_name") + ".xml", map);
        String res = "SUCCESS 生成【activity_verification_" + map.get("class_name") + ".xml】成功";
        return res;
    }

    /**
     * 输出ItemViewModel代码
     */
    public String ItemViewModelAutoWrite(Map<String, Object> map) throws IOException, TemplateException {
        FreemarkerUtil.initConfig(0, "XXXItemViewModel.ftl");
        // 生成Activity代码
        FreemarkerUtil.generator(outFilePath.getAndroidOutPath() + outFilePath.activityPath + map.get("classname") + "\\\\" + map.get("ClassName") + "ItemViewModel.java", map);
        String res = "SUCCESS 生成【" + map.get("ClassName") + "ItemViewModel.java】成功";
        return res;
    }

    /**
     * 输出Adapter代码
     */
    public String AdapterAutoWrite(Map<String, Object> map) throws IOException, TemplateException {
        FreemarkerUtil.initConfig(0, "XXXRecyclerViewBindingAdapter.ftl");
        // 生成Activity代码
        FreemarkerUtil.generator(outFilePath.getAndroidOutPath() + outFilePath.activityPath + map.get("classname") + "\\\\" + map.get("ClassName") + "RecyclerViewBindingAdapter.java", map);
        String res = "SUCCESS 生成【" + map.get("ClassName") + "RecyclerViewBindingAdapter.java】成功";
        return res;
    }

    /**
     * 输出DetailXML代码
     */
    public String DetailXMLAutoWrite(Map<String, Object> map) throws IOException, TemplateException {
        FreemarkerUtil.initConfig(0, "item_verification_xxx_list.ftl");
        // 生成Activity代码
        FreemarkerUtil.generator(outFilePath.getAndroidOutPath() + outFilePath.activity_path + "item_verification_" + map.get("class_name") + "_list.xml", map);
        String res = "SUCCESS 生成【item_verification_" + map.get("class_name") + "_list.xml】成功";
        return res;
    }


}
